#include "String.h"
#include "StringBuilder.h"
#include "LinkedList.h"
#include "ArrayList.h"

static void testeFn()
{
	V(String, teste);
	P(String, teste2);

	RETURN;
}

static void testeFn2()
{
	V(String, teste);
	V(String, teste2);

	RETURN;
}

void printArgs(int argc, char **argv)
{
	int i;
	for(i=0; i<argc; i++)
	{
		printf("%d %s\n", i, argv[i]);
	}
}

int main(int argc, char **argv)
{
	int i;
    setupLibIF(argc,argv);

	V(String, teste);
	V(String, teste2);
	P(String, teste3);

	String *str = StringI()->create();
	String str2 = *str;

	StringI()->setPChar(str,"teste");

I(str)->setPChar(str,"teste");
printf("INSTANCE OF %d %d %d\n",str IS INSTANCEOF(String), str IS INSTANCEOF(None), str IS INSTANCEOF(List));
printf ("%x %x\n", StringI ()-> pchar, findFN (StringI (),"pchar"));
	String *p = StringI()->pos(str,3);
	printf("%s %d %d\n",StringI()->pchar(p),StringI()->endsPChar(str,"ste"),StringI()->compareTo(str,teste3));

//	String *repl = StringI()->replaceAll(str,"te","ca");
String *repl = CALL(str, replaceAll,"te","ca");

	printf("REPL %s\n",StringI()->pchar(repl));


	C(str,setPChar)( C(repl,pchar)() );
	printf("HASHS %d %d\n",C(str,hash)(),C(repl,hash)());

int (*hashPtr)(void*) = findFN(findIF("String"),"hash");
	printf("Reflection Hashs: %d %d\n",hashPtr(str),hashPtr(repl));


List *l1 = (List *)LinkedListI()->create();
List *l2 = (List *)ArrayListI()->create();
List *l3 = (List *)ArrayListI()->create();

printf("SAMETYPE OF %d %d %d\n",str IS SAMETYPEOF(teste3), l1 IS SAMETYPEOF(l2), l2 IS SAMETYPEOF(l3));

	D(str);

	I(&teste)->setPChar(&teste,"teste2");
	printf("%s %d\n",StringI()->pchar(&teste),StringI()->endsPChar(&teste,"ste2"));

	testeFn();
	testeFn2();

	printf("FIND %x %x\n", findIF("String"), StringI());
A (findIF("String")->create());
A (findIF("String")->create());

printf("size 1 %d\n",I(l1)->size(l1));
printf("size 2 %d\n",I(l2)->size(l2));

I(l2)->add(l2,l1);
I(l2)->add(l2,l1);
I(l2)->insertAt(l2,1,0);
I(l2)->insertAt(l2,3,0);
I(l2)->insertAt(l2,10,l1);
I(l2)->set(l2,20,l1);
for(i=0;i<I(l2)->size(l2);i++)
{
	printf("%x ",I(l2)->get(l2,i));
}
printf("\n");

I(l2)->delObj(l2,l1);
for(i=0;i<I(l2)->size(l2);i++)
{
	printf("%x ",I(l2)->get(l2,i));
}
printf("\n");

I(l2)->del(l2,1);
for(i=0;i<I(l2)->size(l2);i++)
{
	printf("%x ",I(l2)->get(l2,i));
}
printf("\n");

printf("%x\n",INVALID_OBJ);

StringBuilder *builder = A(StringBuilderI()->create());
I(builder)->appendPChar(builder,"123");
I(builder)->appendPChar(builder," testando");
I(builder)->prependPChar(builder,"testando ");

String *b = A(StringBuilderI()->build(builder));
//printf("BUILDER %s\n",StringI()->pchar(b));

C(teste3, clone)();
//StringI()->clone(teste3)

	RETURN 0;
}
